import Vue from 'vue'
import App from './App.vue'
import router from './router'
// 现在不让使用cdn形式，因此按需导入不能删掉
import './plugins/element.js'
// 导入字体图标
import './assets/fonts/iconfont.css'
import './assets/fonts_sec/iconfont.css'
// 导入全局样式表
import './assets/css/global.css'
import TreeTable from 'vue-table-with-tree-grid'

// 导入 NProgress 包对应的JS和CSS
import NProgress from 'nprogress'
import 'nprogress/nprogress.css'

// 引入轮播图样式表
import 'swiper/css/swiper.css'
import { Notification } from 'element-ui'
// 引入图片预览组件
import preview from 'vue-photo-preview'
import 'vue-photo-preview/dist/skin.css'
Vue.use(preview)

// 引入自定义指令对象
import * as directives from '@/directives'
Object.keys(directives).forEach(key => {
  // 注册
  Vue.directive(key, directives[key])
})

import axios from 'axios'
// 配置请求的跟路径
// axios.defaults.baseURL = 'http://localhost:8080'
// axios.defaults.baseURL = 'http://192.168.43.112:8090'
// axios.defaults.baseURL = 'http://abc01d.vaiwan.com'
// 账号密码登录后端
// axios.defaults.baseURL = 'http://82.157.239.70:8080'
axios.defaults.baseURL = 'http://114.116.10.5:8070'
// axios.defaults.baseURL = 'http://abc01de.vaiwan.com'
// axios.defaults.timeout = 20000

// axios.defaults.baseURL = 'http://abc01d.vaiwan.com'
// axios.defaults.baseURL = 'http://192.168.43.108:8080/'
// 在 request 拦截器中，展示进度条 NProgress.start()
axios.interceptors.request.use(config => {
  // console.log(config)
  NProgress.start()
  config.headers.memberToken = window.sessionStorage.getItem('memberToken')
  // 在最后必须 return config
  return config
})
// 在 response 拦截器中，隐藏进度条 NProgress.done()
axios.interceptors.response.use(response => {
  // console.log('response',response)
  // 响应码为300时，身份认证过期，需要重新登录
  if (response.data.code === 300) {
    sessionStorage.clear()
    Notification.error({
      title: '提示 ',
      message: '身份认证已过期，请重新登录！'
    })
    router.replace('/login')
  }
  NProgress.done()
  return response
})
Vue.prototype.$http = axios

Vue.config.productionTip = false

Vue.component('tree-table', TreeTable)

Vue.filter('dateFormat', function(originVal) {
  const dt = new Date(originVal)

  const y = dt.getFullYear()
  const m = (dt.getMonth() + 1 + '').padStart(2, '0')
  const d = (dt.getDate() + '').padStart(2, '0')

  const hh = (dt.getHours() + '').padStart(2, '0')
  const mm = (dt.getMinutes() + '').padStart(2, '0')
  const ss = (dt.getSeconds() + '').padStart(2, '0')

  return `${y}-${m}-${d} ${hh}:${mm}:${ss}`
})

new Vue({
  router,
  render: h => h(App)
}).$mount('#app')
